<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('otherJS.taskTitle')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('otherJS.pleaseEnterTaskTitleQuery')" v-model="queryParam.taskTitle"></a-input>
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">{{$t('setailManagement.query')}}</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">{{$t('setailManagement.reset')}}</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <!-- <div class="table-operator"  style="margin-top: 5px">
          <a-button v-if="btnEnableList.indexOf(1)>-1" @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-dropdown>
            <a-menu slot="overlay">
              <a-menu-item key="1" v-if="btnEnableList.indexOf(1)>-1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button>
              批量操作 <a-icon type="down" />
            </a-button>
          </a-dropdown>
        </div> -->
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            @change="handleTableChange">
            <span slot="numberCustomRender" slot-scope="text, record">
              <a @click="myHandleDetail(record)">{{record.taskTitle}}</a>
            </span>
            <span slot="action" slot-scope="text, record">
               <a @click="progressQuery(record)">{{$t('otherJS.progressView')}}</a>
               <a-divider  type="vertical" />
               <a @click="history(record)">{{$t('otherJS.approvalHistory')}}</a>
            </span>
          </a-table>
        </div>
        <a-modal :visible="historyVisible" :width="1500" :title="$t('otherJS.approvalHistory')" :footer="null" @cancel="historyCancel()">
           <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="historyColumns"
            :dataSource="historyDataSource"
            :scroll="scroll"
            :loading="loading"
            >
          </a-table>
        </a-modal>
        <a-modal :visible="progressQueryVisible" :width="1200" :title="$t('otherJS.progressView')" :footer="null" @cancel="progressQueryCancel()">
           <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="progressQueryColumns"
            :dataSource="progressQueryDataSource"
            :scroll="scroll"
            :loading="loading"
            >
          </a-table>
        </a-modal>
        <bill-detail ref="modalDetail"></bill-detail>
        <FinancialDetail ref="financialDetail"></FinancialDetail>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <!-- <workflow-config-modal ref="modalForm" @ok="modalFormOk"></workflow-config-modal>
        <config-role-function-modal ref="configRoleFunctionModal" @ok="configRoleFunction"></config-role-function-modal>
        <workflow-config-set-user ref="WorkflowConfigSetUser" @ok="WorkflowConfigDetailModal"></workflow-config-set-user> -->
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- b y 7 5 2 7  1 8 9 2 0 -->
<script>
  // import WorkflowConfigModal from '../workflow/modules/WorkflowConfigModal'
  // import ConfigRoleFunctionModal from './modules/ConfigRoleFunctionModal'
  // import WorkflowConfigSetUser from './modules/WorkflowConfigSetUser'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BillDetail from '../bill/dialog/BillDetail'
  import FinancialDetail from '../financial/dialog/FinancialDetail'
  import {finanialArr} from '@/utils/detailType'

  import { filterObj} from '@/utils/util'
  import { deleteAction, getAction, postAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
  import {findBillDetailByNumber,findFinancialDetailByNumber } from '@/api/api'

  export default {
    name: "AlreadyApprovalList",
    mixins:[JeecgListMixin],
    components: {
      // WorkflowConfigSetUser,
      // WorkflowConfigModal,
      // ConfigRoleFunctionModal,
      FinancialDetail,
      BillDetail,
      JDate
    },
    data () {
      return {
        roleFunctionModalVisible: false,
        currentRoleId: '',
        historyVisible: false,
        progressQueryVisible: false,
        progressQueryDataSource: [],
        historyDataSource: [],
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        // 查询条件
        queryParam: {name:'',type:'pass'},
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:40,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          { title: this.$t('otherJS.taskTitle'), align:"center", dataIndex: 'taskTitle', width:220,scopedSlots: { customRender: 'numberCustomRender' } },
          { title: this.$t('otherJS.DocumentType'), align:"center", dataIndex: 'flowKey', width:150 },
          { title: this.$t('otherJS.ApprovalComments'), align:"center", dataIndex: 'approveMsg', width:150 },
          { title: this.$t('otherJS.Approver'), align:"center", dataIndex: 'approveName', width:150 },
          { title: this.$t('otherJS.ApprovalType'), align:"center", dataIndex: 'approveType', width:80 },
          { title: this.$t('otherJS.link'), align:"center", dataIndex: 'attribute1', width:150 },
          { title: this.$t('otherJS.ApprovalTime'), align:"center", dataIndex: 'approveDate', width:100 },
          { title: this.$t('setailManagement.startTime'), align:"center", dataIndex: 'beginDate', width:100 },
          { title: this.$t('otherJS.Step'), align:"center", dataIndex: 'process', width:80 },
          { title: this.$t('financialManagement.remarks'), align:"center", dataIndex: 'remark', width:150 },
          {
            title: this.$t('setailManagement.operation'),
            dataIndex: 'action',
            width:150,
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        historyColumns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),
            dataIndex: '',
            key:'rowIndex',
            width:40,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          { title: this.$t('otherJS.LinkName'), align:"center", dataIndex: 'attribute1', width:100 },
          { title: this.$t('otherJS.taskTitle'), align:"center", dataIndex: 'taskTitle', width:200 },
          { title: this.$t('otherJS.Approver'), align:"center", dataIndex: 'loginName', width:80 },
          { title: this.$t('setailManagement.startTime'), align:"center", dataIndex: 'createDateStr', width:100 },
          { title: this.$t('otherJS.AuditType'), align:"center", dataIndex: 'enableFlag', width:100 },
          { title: this.$t('purchasingManagement.ReviewOpinion'), align:"center", dataIndex: 'rmk', width:100 },
          { title: this.$t('otherJS.DocumentType'), align:"center", dataIndex: 'flowKey', width:100 },
          { title: this.$t('otherJS.ApprovalTime'), align:"center", dataIndex: 'lastUpdateDateStr', width:100 },
        ],
        progressQueryColumns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:'3%',
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          { title: this.$t('otherJS.LinkName'), align:"center", dataIndex: 'activityName', width:'3%' },
          // { title: '审批人类型', align:"center", dataIndex: 'typeCode', width:100 },
          { title: this.$t('otherJS.Step'), align:"center", dataIndex: 'process', width:'3%' },
          { title: this.$t('otherJS.AuditType'), align:"center", dataIndex: 'enableFlag', width:'3%' },
        ],
        url: {
          list: "/workflowConfigProcess/ProcessApproveList",
          delete: "/workflowConfig/delete",
          deleteBatch: "/workflowConfig/deleteBatch",
        }
      }
    },
    computed: {

    },
    created () {
    },
    methods: {
      
      getQueryParams () {
        //获取查询条件
        let sqp = {}
        if (this.superQueryParams) {
          sqp['superQueryParams'] = encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        let searchObj = {}
        delete this.queryParam.beginTime
        delete this.queryParam.endTime
        searchObj.search = JSON.stringify(this.queryParam)
        var param = Object.assign(sqp, searchObj, this.isorter, this.filters)
        param.field = this.getQueryField()
        // param.promotionType = this.promotionType
        param.currentPage = this.ipagination.current
        param.pageSize = this.ipagination.pageSize
        return filterObj(param)
      },
      // return modalDetail name 
      getModelName(type){
        const financialTypes = finanialArr
        console.log(financialTypes.includes(v=>v.zh === type));
        if(financialTypes.find(v=>v.zh === type)){
          return 'financialDetail'
        }else{
          return 'modalDetail' 
        }
      },
      history(val) {
        this.historyVisible = true;
        let param = {
          defineDetailId: val.processDetailId
        }
        getAction('/workflowConfigProcess/getHistoryInfo', param).then((res) => {
          if (res.code == 200) {
            this.historyDataSource = res.data
          }
        })
      },
      progressQuery(val) {
        this.progressQueryVisible = true;
        let param = {
          defineDetailId: val.configId,
          processDetailId: val.processDetailId
        }
        getAction('/workflowConfigProcess/getProgressInfo', param).then((res) => {
          if (res.code == 200) {
            console.log(res.data)
            this.progressQueryDataSource = res.data
          }
        })
      },
      historyCancel(){
        this.historyVisible = false;
      },
      progressQueryCancel(){
        this.progressQueryVisible = false;
      },
      myHandleDetail(record) {
      let modalName = this.getModelName(record.flowKey)
        if(modalName === 'financialDetail'){
            findFinancialDetailByNumber({ billNo: record.sysOwnerCpy }).then((res) => {
            if (res && res.code === 200) {
              this.handleDetail(res.data, record.flowKey);
            }
          })
        }else{
          findBillDetailByNumber({ number: record.sysOwnerCpy }).then((res) => {
          if (res && res.code === 200) {
            this.handleDetail(res.data, record.flowKey);
          }
        })
        }
        
      },
      handleDetail: function (record, type) {
      console.log(record, type, 'jeecgListMixin')
      let modalName = this.getModelName(type)
      this.$refs[modalName].show(record, type)
      this.$refs[modalName].title = type + '-详情'
      },
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = this.$t('setailManagement.edit');
        this.$refs.modalForm.disableSubmit = false;
        if(this.btnEnableList.indexOf(1)===-1) {
          this.$refs.modalForm.isReadOnly = true
        }
      },
      handleSetFunction(record) {
        this.$refs.configRoleFunctionModal.edit(record);
        this.$refs.configRoleFunctionModal.title = this.$t('systemManagement.allocationFunction');
        this.$refs.configRoleFunctionModal.disableSubmit = false;
      },
      detailUser(record) {
        this.$refs.WorkflowConfigSetUser.edit(record);
        this.$refs.WorkflowConfigSetUser.title = this.$t('inPrint.assignPermissions');
        this.$refs.WorkflowConfigSetUser.disableSubmit = false;
        // if(this.btnEnableList.indexOf(1)===-1) {
        //   this.$refs.modalForm.isReadOnly = true
        // }
      },
      configRoleFunction(id) {
        //重载列表
        this.loadData();
        this.roleFunctionModalVisible = true;
        this.currentRoleId = id
      },
      WorkflowConfigDetailModal(id) {
        //重载列表
        this.loadData();
        this.roleFunctionModalVisible = true;
        this.currentRoleId = id
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>